package queuecode;

import java.util.Random;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/14 15:03
 */
public class Main {

    /**
     * 测试使用队列q 操作opCount 个数字需要的时间
     * @param q
     * @param opCount 操作的次数
     * @return 时间 单位：s
     */
    private static double testQueue(Queue<Integer> q,int opCount){
        long startTime =System.nanoTime();

        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            q.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            q.dequeue();
        }


        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }




    public static void main(String[] args) {
        int  opCount = 100000;
        ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
        double time1 = testQueue(arrayQueue,opCount);
        System.out.println("ArrayQueue,time:"+time1+" s");

        LoopQueue<Integer> loopQueue = new LoopQueue<>();
        double time2 = testQueue(loopQueue,opCount);
        System.out.println("LoopQueue,time:"+time2+" s");

    }
}
